package com.example.controller.appointment;

import com.example.common.Result;

import com.example.model.entity.appointment.MedicalCard;
import com.example.service.appointment.MedicalCardService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 病例表前端操作接口
 **/
@RestController
@RequestMapping("/medicalCard")
@Api("病例接口")
public class MedicalCardController {

    @Resource
    private MedicalCardService medicalCardService;

    /**
     * 新增
     */
    @ApiOperation(value = "新增病例")
    @PostMapping("/add")
    public Result add(@RequestBody MedicalCard medicalCard) {
        medicalCardService.add(medicalCard);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除病例信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        medicalCardService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除病例信息")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        medicalCardService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改病例信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody MedicalCard medicalCard) {
        medicalCardService.updateById(medicalCard);
        return Result.success();
    }
    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询病例信息")
    @GetMapping("/selectByRecordId/{recordId}")
    public Result selectByRecordId(@PathVariable Integer recordId) {
        MedicalCard medicalCard = medicalCardService.selectByRecordId(recordId);
        return Result.success(medicalCard);
    }
    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询病例信息")
    @GetMapping("/selectByMedicalNum/{medicalNum}")
    public Result selectByMedicalNum(@PathVariable String medicalNum) {
        String medicalCard = medicalCardService.selectByMedicalNum(medicalNum);
        return Result.success(medicalCard);
    }
    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询病例信息")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        MedicalCard medicalCard = medicalCardService.selectById(id);
        return Result.success(medicalCard);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有病例信息")
    @GetMapping("/selectAll")
    public Result selectAll(MedicalCard medicalCard) {
        List<MedicalCard> list = medicalCardService.selectAll(medicalCard);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询病例信息")
    @GetMapping("/selectPage")
    public Result selectPage(MedicalCard medicalCard,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<MedicalCard> page = medicalCardService.selectPage(medicalCard, pageNum, pageSize);
        return Result.success(page);
    }

}
